package com.eshop.config;

import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

@Component
public class MetaHandler implements MetaObjectHandler
{
    private static final Logger log;
    
    public void insertFill(final MetaObject metaObject) {
        try {
            final Timestamp time = new Timestamp(System.currentTimeMillis());
            if (metaObject.hasSetter("createTime")) {
                MetaHandler.log.debug("自动插入 createTime");
                this.setFieldValByName("createTime", (Object)time, metaObject);
            }
            if (metaObject.hasSetter("updateTime")) {
                MetaHandler.log.debug("自动插入 updateTime");
                this.setFieldValByName("updateTime", (Object)time, metaObject);
            }
            if (metaObject.hasSetter("createDate")) {
                MetaHandler.log.debug("自动插入 createDate");
                this.setFieldValByName("createDate", (Object)time, metaObject);
            }
            if (metaObject.hasSetter("updateDate")) {
                MetaHandler.log.debug("自动插入 updateDate");
                this.setFieldValByName("updateDate", (Object)time, metaObject);
            }
            if (metaObject.hasSetter("delFlag")) {
                MetaHandler.log.debug("自动插入 delFlag");
                this.setFieldValByName("delFlag", (Object)false, metaObject);
            }
            if (metaObject.hasSetter("isDel")) {
                MetaHandler.log.debug("自动插入 isDel");
                this.setFieldValByName("isDel", (Object)0, metaObject);
            }
            if (metaObject.hasSetter("addTime")) {
                final String timestamp = String.valueOf(System.currentTimeMillis() / 1000L);
                this.setFieldValByName("addTime", (Object)Integer.valueOf(timestamp), metaObject);
            }
        }
        catch (Exception e) {
            MetaHandler.log.error("自动注入失败:{}", (Throwable)e);
        }
    }
    
    public void updateFill(final MetaObject metaObject) {
        try {
            final Timestamp time = new Timestamp(System.currentTimeMillis());
            if (metaObject.hasSetter("updateTime")) {
                MetaHandler.log.debug("自动插入 updateTime");
                this.setFieldValByName("updateTime", (Object)time, metaObject);
            }
            if (metaObject.hasSetter("updateDate")) {
                MetaHandler.log.debug("自动插入 updateDate");
                this.setFieldValByName("updateDate", (Object)time, metaObject);
            }
            if (metaObject.hasSetter("delFlag")) {
                MetaHandler.log.debug("自动插入 delFlag");
                this.setFieldValByName("delFlag", (Object)null, metaObject);
            }
            if (metaObject.hasSetter("createTime")) {
                MetaHandler.log.debug("自动插入 createTime");
                this.setFieldValByName("createTime", (Object)null, metaObject);
            }
        }
        catch (Exception e) {
            MetaHandler.log.error("自动注入失败:{}", (Throwable)e);
        }
    }
    
    static {
        log = LoggerFactory.getLogger((Class)MetaHandler.class);
    }
}
